package org.hiside.android.travel.line.adapter;

import org.hiside.android.travel.R;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class TitleGridAdapter extends BaseAdapter {
    int[] titles = new int[] { R.string.Sun, R.string.Mon, R.string.Tue, R.string.Wed, R.string.Thu, R.string.Fri,
            R.string.Sat };

    private Activity activity;

    // construct
    public TitleGridAdapter(Activity a) {
        activity = a;
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public Object getItem(int position) {
        return titles[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LinearLayout iv = new LinearLayout(activity);
        TextView txtDay = new TextView(activity);
        txtDay.setFocusable(false);
        txtDay.setBackgroundColor(Color.TRANSPARENT);
        iv.setOrientation(1);

        txtDay.setGravity(Gravity.CENTER);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

        int i = (Integer) getItem(position);

        txtDay.setTextColor(Color.WHITE);
        Resources res = activity.getResources();

        if (i == R.string.Sat) {
            // 周六
            txtDay.setBackgroundColor(res.getColor(R.color.title_text_6));
        } else if (i == R.string.Sun) {
            // 周日
            txtDay.setBackgroundColor(res.getColor(R.color.title_text_7));
        } else {

        }

        txtDay.setText((Integer) getItem(position));

        iv.addView(txtDay, lp);

        return iv;
    }
}
